import pop from '../utils/pop';
import env from '../config/env.js';
const ticket = localStorage.ticket;
const prefix = env.gwApiPrefix;
const errorHandler = error => {
	pop.error("加载数据失败！");
	console.log(error);
}

export default {
	//购物车列表
	carts(){
		return `${prefix}/api/zsapi/trade/carts?ticket=${ticket}`;
	},
	//加入购物车
	joinCart(goodsId){
		const data = {
			 goodsId : goodsId,
			 num : 1
		}
		return axios.post(`${prefix}/api/zsapi/trade/carts?ticket=${ticket}`,data).catch(errorHandler);
	},
	//移除购物车
	deleteCart(id){
		return axios.delete(`${prefix}/api/zsapi/trade/carts/${id}?ticker=${ticket}`).catch(errorHandler);
	},
	
	
	//立即购买、添加订单
	submit(data){
		return axios.post(`${prefix}/api/zsapi/trade/orders?ticket=${ticket}`,data).catch(errorHandler);
	},
	//订单详情
	orders(orderId){
		return axios.get(`${prefix}/api/zsapi/trade/orders/${orderId}?ticket=${ticket}`).catch(errorHandler);
	},
	//支付
	pay(data){
		return axios.post(`${prefix}/api/zsapi/trade/orders/pay?ticket=${ticket}`,data).catch(errorHandler);
	}
}